package com.jdplat.jdm.core.spring;

import java.io.Serializable;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import com.jdplat.jdm.core.web.dao.BaseDao;

/**
 * Created by qirp on 2016/11/15.
 */
public class SpringContext<Entity,PK extends Serializable> extends BaseDao<Entity, PK> implements ApplicationContextAware {

    private static ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext appCtx) {
        applicationContext = appCtx;
    }

    public static ApplicationContext getApplicationContext() {
        return applicationContext;
    }

    public static <T> T getBean(Class<T> clazz) {
        return (T) applicationContext.getBean(clazz);
    }

    public static Object getBean(String beanName) {
        return applicationContext.getBean(beanName);
    }
}
